home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / AUDIO / AUDIO / GSMUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-08-20  |  3KB  |  142 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   audio, StdCtrls, ExtCtrls, mmsystem;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Button2: TButton;
  13.     Panel1: TPanel;
  14.     WaveIn1: TWaveIn;
  15.     WaveOut1: TWaveOut;
  16.     Button3: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure Button2Click(Sender: TObject);
  19.     procedure WaveIn1WaveInData(Data: PChar; Size: Integer);
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure Button3Click(Sender: TObject);
  22.     procedure WaveOut1WaveOutDone(Sender: TObject);
  23.     procedure FormDestroy(Sender: TObject);
  24.     procedure WaveIn1BeforeOpen(var WaveFormat: Pointer);
  25.   private
  26.     { Private declarations }
  27.   public
  28.     { Public declarations }
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. uses msacm32;
  37.  
  38. Var
  39.  i : integer;
  40.  PAudioBuf, AudioBuf : PChar;
  41.  
  42. {$R *.DFM}
  43.  
  44.  pafd  : TACMFORMATDETAILSA;
  45. // GSMWaveFormat : TGSM610WaveFormat;
  46.  GSMWaveFormat : TTRUESPEECHWAVEFORMAT ;
  47.  
  48. function acmFormatEnumCallback(hadid : THANDLE;pafd : PACMFORMATDETAILSA; dwInstance, fdwSupport : DWORD ):BOOL; stdcall;
  49. begin
  50.   Result := True;             {WAVE_FORMAT_DIGISTD}
  51.   if pafd.pwfx^.wFormatTag = WAVE_FORMAT_GSM610 then begin
  52.      move(pafd.pwfx^, GSMWaveFormat, sizeof(GSMWaveFormat));
  53.      Result := False;
  54.   end;
  55.  
  56. end;
  57.  
  58. procedure TForm1.WaveIn1BeforeOpen(var WaveFormat: Pointer);
  59. var
  60.  i,
  61.  MaxSizeFormat : integer;
  62. begin
  63.   acmMetrics(0, ACM_METRIC_MAX_SIZE_FORMAT, @MaxSizeFormat);
  64.   pafd.cbStruct := sizeof(pafd);
  65.   pafd.dwFormatTag := 0;
  66.   getmem(pafd.pwfx, MaxSizeFormat);
  67.   pafd.cbWfx := MaxSizeFormat;
  68.   with PWaveFormatEx(pafd.pwfx)^ do begin
  69.    wFormatTag := WAVE_FORMAT_PCM;
  70.    nChannels := 1;
  71.    nSamplesPerSec := WaveIn1.Samples;
  72.    nAvgBytesPerSec:= WaveIn1.Samples; { for buffer estimation }
  73.    nBlockAlign:=1;      { block size of data }
  74.    wbitspersample := 8;
  75.    //cbSize := 0;
  76.   end;
  77.  
  78.  
  79.   move(PWaveFormatEx(pafd.pwfx)^, GSMWaveFormat, sizeof(GSMWaveFormat));
  80.  
  81.   i := acmFormatEnumA(0, @pafd, acmFormatEnumCallback, hInstance, ACM_FORMATENUMF_CONVERT);
  82.  
  83.   if i = 0 then begin
  84.      // Open the audio device with the GSM Wave Format structure
  85.      // You must open the waveout component with the same WaveFormat structure
  86.      // WRITE YOUR CODE FOR THE ABOVE
  87.      // I'm always here for questions
  88.      //
  89.      WaveFormat := @GSMWaveFormat;
  90.   end;
  91.  
  92. end;
  93.  
  94. procedure TForm1.FormCreate(Sender: TObject);
  95. begin
  96.  GetMem(AudioBuf, 200000);
  97.  PAudioBuf := AudioBuf;
  98. end;
  99.  
  100. procedure TForm1.FormDestroy(Sender: TObject);
  101. begin
  102.  FreeMem(AudioBuf);
  103. end;
  104.  
  105. procedure TForm1.WaveIn1WaveInData(Data: PChar; Size: Integer);
  106. begin
  107.   inc(I, Size);
  108.   Panel1.Caption := Format('%d Bytes recorded', [i]);
  109.   move(Data^, PAudioBuf^, size);
  110.   inc(PAudioBuf, Size);
  111. end;
  112.  
  113. procedure TForm1.Button3Click(Sender: TObject);
  114. Var
  115.  Size : Integer;
  116. begin
  117.   Size := Abs(Integer(PAudioBuf) - Integer(AudioBuf) ) ;
  118.   PAudioBuf := AudioBuf;
  119.   WaveOut1.Open;
  120.   WaveOut1.PlayBack(AudioBuf, Size);
  121. end;
  122.  
  123. procedure TForm1.WaveOut1WaveOutDone(Sender: TObject);
  124. begin
  125.   WaveOut1.Close;
  126. end;
  127.  
  128. procedure TForm1.Button1Click(Sender: TObject);
  129. begin
  130.  i := 0;
  131.  // You may use WaveIn1.Open method also 
  132.  wavein1.Recording := True;
  133. end;
  134.  
  135. procedure TForm1.Button2Click(Sender: TObject);
  136. begin
  137.  wavein1.Recording := False;
  138. end;
  139.  
  140.  
  141. end.
  142.